package com.example.mystore.dao;


import com.example.mystore.utils.LinkMySQL;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

public class CategoryDao {
    public static HashMap<Integer,String> selectCategory(){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        HashMap<Integer,String> hashMap = new HashMap();
        try {
            conn = LinkMySQL.getConnection();
            String sql = "select * from commoditytype ";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                hashMap.put(rs.getInt("type_id"),rs.getString("type_name"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            LinkMySQL.release(rs,pstmt,conn);
        }
        return hashMap;
    }
}
